import java.util.Arrays;

public class MaxArea {
    //盛最多水的容器
    public int maxArea(int[] height) {
        int left = 0;
        int right = height.length - 1;
        int ret = 0;

        while (left < right){
            int v = Math.min(height[right], height[left]) * (right - left);
            ret = Math.max(ret, v);

            if (height[right] < height[left]){
                right--;
            }else{
                left++;
            }
        }

        return ret;
    }

    public static void main(String[] args) {
        MaxArea test = new MaxArea();
        test.triangleNumber(new int[]{2, 3, 4, 4});
    }
    public int triangleNumber(int[] nums) {
        Arrays.sort(nums);

        int n = nums.length;
        int ret = 0;
        for (int i = n - 1; i >= 2; i--){
            int left = 0, right = i - 1;

            while (left < right){
                if (nums[left] + nums[right] > nums[i]){
                    ret += (right - left);
                    right--;
                }else{
                    left++;
                }
            }

        }

        return ret;
    }
}
